package priv.lhy.zipkin.gateway.filter;

import brave.Tracer;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

/**
 * @author: lihy
 * date: 2019/11/6 11:23
 * description:
 */
@Component
public class LoggerFilter extends ZuulFilter {

    @Autowired
    private Tracer tracer;

    @Override
    public String filterType() {
        return FilterConstants.POST_TYPE;
    }

    @Override
    public int filterOrder() {
        return 900;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        tracer.currentSpan().tag("operator", "forezp");
        tracer.currentSpan().tag("user", "lhy");
        System.out.println(tracer.currentSpan().context().traceId());
        return null;
    }
}
